home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Microsoft Plateform / Visual Basic 5.0 / Msvb50.ace / msvb50 / MSVB50 / VB / SAMPLES / VISDATA / ATTACH.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-10-16  |  5.9 KB  |  193 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAttachments 
  3.    Caption         =   "Attachments"
  4.    ClientHeight    =   2895
  5.    ClientLeft      =   3870
  6.    ClientTop       =   2595
  7.    ClientWidth     =   6075
  8.    HelpContextID   =   2016086
  9.    Icon            =   "ATTACH.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   2895
  14.    ScaleWidth      =   6075
  15.    ShowInTaskbar   =   0   'False
  16.    Begin VB.ListBox lstTables 
  17.       Height          =   2430
  18.       Left            =   30
  19.       MultiSelect     =   1  'Simple
  20.       Sorted          =   -1  'True
  21.       TabIndex        =   4
  22.       Top             =   15
  23.       Width           =   6000
  24.    End
  25.    Begin VB.PictureBox picButtons 
  26.       Align           =   2  'Align Bottom
  27.       Appearance      =   0  'Flat
  28.       BorderStyle     =   0  'None
  29.       ForeColor       =   &H80000008&
  30.       Height          =   405
  31.       Left            =   0
  32.       ScaleHeight     =   405
  33.       ScaleWidth      =   6075
  34.       TabIndex        =   0
  35.       Top             =   2484
  36.       Width           =   6075
  37.       Begin VB.CommandButton cmdNew 
  38.          Caption         =   "&New"
  39.          Height          =   330
  40.          Left            =   120
  41.          MaskColor       =   &H00000000&
  42.          TabIndex        =   3
  43.          Top             =   45
  44.          Width           =   1815
  45.       End
  46.       Begin VB.CommandButton cmdReAttach 
  47.          Caption         =   "&ReAttach"
  48.          Height          =   330
  49.          Left            =   2160
  50.          MaskColor       =   &H00000000&
  51.          TabIndex        =   2
  52.          Top             =   45
  53.          Width           =   1845
  54.       End
  55.       Begin VB.CommandButton cmdClose 
  56.          Cancel          =   -1  'True
  57.          Caption         =   "&Close"
  58.          Height          =   330
  59.          Left            =   4200
  60.          MaskColor       =   &H00000000&
  61.          TabIndex        =   1
  62.          Top             =   45
  63.          Width           =   1845
  64.       End
  65.    End
  66. Attribute VB_Name = "frmAttachments"
  67. Attribute VB_GlobalNameSpace = False
  68. Attribute VB_Creatable = False
  69. Attribute VB_TemplateDerived = False
  70. Attribute VB_PredeclaredId = True
  71. Attribute VB_Exposed = False
  72. Option Explicit
  73. '>>>>>>>>>>>>>>>>>>>>>>>>
  74. Const FORMCAPTION = "Attachments"
  75. Const BUTTON1 = "&New"
  76. Const BUTTON2 = "&ReAttach"
  77. Const BUTTON3 = "&Close"
  78. '>>>>>>>>>>>>>>>>>>>>>>>>
  79. Sub cmdClose_Click()
  80.   Unload Me
  81. End Sub
  82. Sub cmdNew_Click()
  83.   frmNewAttach.Show vbModal
  84. End Sub
  85. Sub cmdReAttach_Click()
  86.   On Error GoTo REAErr
  87.   Dim i As Integer
  88.   Dim sTmp As String
  89.   Screen.MousePointer = vbHourglass
  90.   'execute the refreshlink method on all the selected items
  91.   For i = 0 To lstTables.ListCount - 1
  92.     If lstTables.Selected(i) Then
  93.       sTmp = Trim$(Left$(lstTables.Text, InStr(lstTables.Text, vbTab)))
  94.       gdbCurrentDB.TableDefs(sTmp).RefreshLink
  95.     End If
  96.   Next
  97.   MsgBar vbNullString, False
  98.   Screen.MousePointer = vbDefault
  99.   Exit Sub
  100. REAErr:
  101.   ShowError
  102.   If i > 0 Then
  103.     Resume Next    'try to continue
  104.   End If
  105. End Sub
  106. Sub Form_Load()
  107.   On Error GoTo FLErr
  108.   Dim tdf As TableDef
  109.   Dim i As Integer
  110.   Me.Caption = FORMCAPTION
  111.   cmdNew.Caption = BUTTON1
  112.   cmdReAttach.Caption = BUTTON2
  113.   cmdClose.Caption = BUTTON3
  114.   'get the attached tables from the tabledefs collection
  115.   For Each tdf In gdbCurrentDB.TableDefs
  116.     If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Or _
  117.        (tdf.Attributes And dbAttachedODBC) = dbAttachedODBC Then
  118.       lstTables.AddItem tdf.Name & String(32 - Len(tdf.Name), " ") & vbTab & tdf.SourceTableName & "=>" & tdf.Connect
  119.     End If
  120.   Next
  121.   Me.Height = 3360
  122.   Me.Width = 6195
  123.   Me.Top = 1000
  124.   Me.Left = 1000
  125.   Screen.MousePointer = vbDefault
  126.   Exit Sub
  127. FLErr:
  128.   ShowError
  129.   Unload Me
  130. End Sub
  131. Private Sub lstTables_DblClick()
  132.   On Error GoTo GTDErr
  133.   Screen.MousePointer = vbHourglass
  134.   gdbCurrentDB.TableDefs(Trim$(Left$(lstTables.Text, InStr(lstTables.Text, vbTab)))).RefreshLink
  135.   Screen.MousePointer = vbDefault
  136.   Exit Sub
  137. GTDErr:
  138.   ShowError
  139. '  Resume 'x
  140. End Sub
  141. Private Sub Form_Resize()
  142.   On Error Resume Next
  143.   If Me.WindowState = 1 Then Exit Sub
  144.   lstTables.Width = Me.ScaleWidth - (lstTables.Left * 2)
  145.   lstTables.Height = Me.ScaleHeight - (picButtons.Height + 40)
  146. End Sub
  147. Public Sub AddAttachment()
  148.   On Error GoTo AttachErr
  149.   Dim sConnect As String
  150.   Dim tbl As TableDef
  151.   Dim i As Integer
  152.   Dim sTmp As String
  153.   With frmNewAttach
  154.     If DupeTableName(.txtAttachName.Text) Then
  155.       .txtAttachName.SetFocus
  156.       Exit Sub
  157.     End If
  158.     MsgBar "Attaching " & .txtAttachName.Text, True
  159.     Screen.MousePointer = vbHourglass
  160.     sConnect = .GetConnectStr()
  161.     'set the properties
  162.     Set tbl = gdbCurrentDB.CreateTableDef(.txtAttachName.Text)
  163.     tbl.SourceTableName = .cboTableName.Text
  164.     tbl.Connect = sConnect
  165.     If .chkSavePassword.Value = vbChecked Then
  166.       tbl.Attributes = dbAttachSavePWD
  167.     End If
  168.     If .chkExclusive.Value = vbChecked Then
  169.       tbl.Attributes = tbl.Attributes Or dbAttachExclusive
  170.     End If
  171.     gdbCurrentDB.TableDefs.Append tbl
  172.     'make sure and remove it if it was overwritten
  173.     For i = 0 To lstTables.ListCount - 1
  174.       sTmp = Trim$(Left$(lstTables.List(i), InStr(lstTables.List(i), vbTab)))
  175.       If UCase(sTmp) = UCase(.txtAttachName.Text) Then
  176.         lstTables.RemoveItem i
  177.         Exit For
  178.       End If
  179.     Next
  180.     'add it to the list
  181.     lstTables.AddItem .txtAttachName.Text & String(32 - Len(.txtAttachName.Text), " ") & vbTab & .cboTableName.Text & "=>" & sConnect
  182.     Screen.MousePointer = vbDefault
  183.     .txtAttachName.Text = vbNullString
  184.     .cboTableName.Text = vbNullString
  185.   End With
  186.   MsgBar vbNullString, False
  187.   Screen.MousePointer = vbDefault
  188.   Exit Sub
  189. AttachErr:
  190.   ShowError
  191. '  Resume 'x
  192. End Sub
  193.